<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增App版本更新')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-version-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">版本号：</label>
                <div class="col-sm-8">
                    <input id="versionCode" placeholder="数字，必须比以前的都大" required name="versionCode" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">版本名称：</label>
                <div class="col-sm-8">
                    <input id="versionName" name="versionName" required placeholder="如v1.1.1"  class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input id="title" name="title" placeholder="标题" required class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <input id="content" name="content" placeholder="更新内容，\n换行" required class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">平台：</label>
                <div class="col-sm-8">
                    <select id="platform" name="platform" class="form-control m-b" >
                        <option value="android">安卓</option>
                        <option value="ios">ios</option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <select id="type" name="type" class="form-control m-b" >
                        <option value="0">用户端</option>
                        <option value="1">社工端</option>
                        <option value="2">其他</option>
                    </select>
                </div>
            </div>

            <div class="form-group" id="filePath" name="filePath">
                <label class="col-sm-3 control-label">路径：</label>
                <div class="col-sm-8">
                    <input id="file" name="file"  placeholder="苹果无需上传" class="form-control" type="file">
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label">上传路径：</label>
                <div class="col-sm-8">
                    <input id="path" name="path" placeholder="苹果填写，android填写无效" class="form-control" type="text">
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label">是否强制更新：</label>
                <div class="col-sm-8">
                    <select id="isMustUpdate" name="isMustUpdate" class="form-control m-b" >
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "jiajia/version"
        $("#form-version-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                uploadFile("#file",function (res) {
                    $("#path").val(res.url);
                })
                $.operate.save(prefix + "/add", $('#form-version-add').serialize());
            }
        }

        $("input[name='addtime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var formData = new FormData();
                formData.append('file',$(file)[0].files[0]);
                $.modal.loading("文件上传中，请稍后...")
                $.ajax({
                    url: "/common/admin/upload/up/single",
                    data: formData,
                    type: "post",
                    dataType: "json",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                        $("#path").val(result.url);
                        $.operate.save(prefix + "/add", $('#form-version-add').serialize());
                }
            })
        }


            }

        function uploadFile(idSelector,callback) {
            var formData = new FormData();
            formData.append('file',$(idSelector)[0].files[0]);
            $.modal.loading("上传中，请稍后...")
            $.ajax({
                    url: "/common/admin/upload/up/single",
                data: formData,
                type: "post",
                dataType: "json",
                processData: false,
                contentType: false,
                success: function(result) {
                    $.modal.closeLoading();
                    callback(result)
                }
            })
        }

        // $(function() {
        //     $('.summernote').summernote({
        //         lang: 'zh-CN',
        //         dialogsInBody: true,
        //         callbacks: {
        //             onChange: function(contents, $edittable) {
        //                 $("input[name='" + this.id + "']").val(contents);
        //             },
        //             onImageUpload: function(files) {
        //                 var obj = this;
        //                 var data = new FormData();
        //                 data.append("file", files[0]);
        //                 $.ajax({
        //                     type: "post",
        //                     url: ctx + "common/upload",
        //                     data: data,
        //                     cache: false,
        //                     contentType: false,
        //                     processData: false,
        //                     dataType: 'json',
        //                     success: function(result) {
        //                         if (result.code == web_status.SUCCESS) {
        //                             $('#' + obj.id).summernote('insertImage', result.url);
        //                         } else {
        //                             $.modal.alertError(result.msg);
        //                         }
        //                     },
        //                     error: function(error) {
        //                         $.modal.alertWarning("图片上传失败。");
        //                     }
        //                 });
        //             }
        //         }
        //     });
        // });
    </script>
</body>
</html>
